<template>
  <!-- 抽取记录页面 -->
  <div class="fillcontain">
    <el-form
      :model="searchParams"
      ref="ruleForm"
      label-width="100px"
      class="search_container"
    >
      <el-row>
        <el-col :span="6">
          <el-form-item label="文件名称：" class="text_center">
            <el-input
              v-model="searchParams.rulePkgName"
              placeholder="请输入"
              clearable
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6" class="text_center">
          <el-form-item label="文件类型：">
            <el-select
              v-model="searchParams.status"
              placeholder="请选择"
              clearable
            >
              <el-option
                v-for="item in statusDic"
                :key="item.id"
                :label="item.dictValue"
                :value="item.id + ''"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="抽取时间：" class="text_center">
            <el-date-picker value-format="yyyy-MM-dd" v-model="searchParams.scanDate" type="date" placeholder="请选择"></el-date-picker>
          </el-form-item>
        </el-col>

        <el-col :span="6" class="text_center">
          <el-button
            type="primary"
            icon="el-icon-search"
            @click="getList"
          ></el-button>
          <el-button
            type="primary"
            plain
            icon="el-icon-refresh"
            @click="resetSearch"
          ></el-button>
        </el-col>
      </el-row>
    </el-form>

    <div class="contain">
      <div class="table_container">
        <el-table
          v-loading="loading"
          :data="tableData"
          highlight-current-row
          height="calc(100vh - 335px)"
          header-cell-class-name="table-header-class"
          style="width: 100%"
        >
          <el-table-column
           align="center" 
           type="index" 
           width="80" 
           label="序号">
          </el-table-column>

          <el-table-column
            min-width="170"
            property="rulePkgCode"
            label="文件名"
            align="center"
            show-overflow-tooltip
          >
          </el-table-column>

          <el-table-column
            min-width="120"
            property="rulePkgName"
            label="类型"
            align="center"
            show-overflow-tooltip
          >
          </el-table-column>

          <el-table-column
            min-width="110"
            property="remark"
            label="抽取方式"
            align="center"
            show-overflow-tooltip
          >
          </el-table-column>

          <el-table-column
            min-width="120"
            property="remark"
            label="状态"
            align="center"
            show-overflow-tooltip
          >
          </el-table-column>

          <el-table-column
            min-width="120"
            property="remark"
            label="抽取人"
            align="center"
            show-overflow-tooltip
          >
          </el-table-column>

          <el-table-column
            min-width="120"
            property="remark"
            label="抽取时间"
            align="center"
            show-overflow-tooltip
          >
          </el-table-column>

          <el-table-column label="操作" align="center" width="100" fixed="right">
            <template slot-scope="scope">
              <div style="display: flex; justify-content: center">
                <span
                  class="handle-btn"
                  @click="handleDetail(scope.row)"
                  >查看</span
                >
                <span
                  class="handle-btn"
                  @click="handleDel(scope.row)"
                  >删除</span
                >
              </div>
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页 -->
				<el-row>
					<el-col :span="24">
						<div class="pagination">
							<el-pagination background v-if='paginations.total > 0' :page-sizes="paginations.pageSizes"
								:page-size="paginations.pageSize" :layout="paginations.layout"
								:total="paginations.total" :current-page='paginations.pageIndex'
								@current-change='handleCurrentChange' @size-change='handleSizeChange'>
							</el-pagination>
						</div>
					</el-col>
				</el-row>
      </div>
    </div>
  </div>
</template>

<script>
import {
  getAiTaskRecordApi
} from "@/api/underwriting/uw"
import constant from "@/utils/constant";
export default {
  data() {
    return {
      statusDic: [],  //发布状态
      searchParams: {
        rulePkgName: "", //规则包名称
        status: "", //状态
      },
      tableData: [],
      loading: false,

      // 分页
      paginations: {
				total: 0, // 总数
				pageIndex: 1, // 当前位于哪页
				pageSize: 10, // 1页显示多少条
				pageSizes: [10, 20, 30, 50], //每页显示多少条
				layout: "total, sizes, prev, pager, next, jumper" // 翻页属性
			},
    };
  },
  created() {
    this.getList();
    this.getNameDictProject()
  },
  mounted() { },
  methods: {
    // 查询逻辑符
    getNameDictProject(){
      getNameDictProjectApi({name: '版本发布状态'}).then(res => {
				if (res.resultCode == constant.SUCCESS) {
					this.statusDic = res.data
				}
			})
    },
    // 点击新增规则包按钮跳转
    add(){
      this.$router.push({
        path: "/home/maintenance/robouUnderwriting/intelligenceRule/rulePackage",query: {type:'add'}
      })
    },
    // 查询列表
    getList(flag) {
      if(flag) this.paginations.pageIndex = 1;
      this.paginations.total = 0;
      let params = {
        pageNum: this.paginations.pageIndex,
        pageSize: this.paginations.pageSize
      }
      for (let key in this.searchParams) {
        if(this.searchParams[key]) params[key] = this.searchParams[key]
      }

      this.$store.dispatch("loading/CHANGE_LOADING", true);
      this.tableData = []
      getAiTaskRecordApi(params).then((res) => {
        this.$store.dispatch("loading/CHANGE_LOADING", false);
        if(res.resultCode == constant.SUCCESS) this.tableData = res.data.list || []
        // 页码赋值
				this.paginations.total = res.data.total;
      })
      .catch((err) => {
        this.$store.dispatch("loading/CHANGE_LOADING", false);
      });
    },
    // 清除查询条件
    resetSearch() {
      this.searchParams = {
        rulePkgName: "", //规则包名称
        status: "", //状态
      }
    },

    // ----列表操作按钮
    // 查看
    handleDetail(row){
      // 先写死假数据
      let extractResultQuery = {
        itemId: row.itemId,
        mainId: row.mainId,
        peOrgCode: row.peOrgCode,
        accepted: row.accepted,
        peCode: row.peCode,
        itemStatus: row.taskStatus,
        // taskNo: row.itemNo,
      }
      sessionStorage.setItem('extractResultQuery',JSON.stringify(extractResultQuery))
      this.$router.push({
        path: "/home/maintenance/robouUnderwriting/intelligenceExtract/extractResult"
      })
    },
    // 删除
    handleDel(row){
      this.$confirm('是否删除此记录?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$message({
          type: 'success',
          message: '删除成功!'
        });
      }).catch(() => {});
    },
    // 每页多少条切换
		handleSizeChange(pageSize) {
			this.paginations.pageSize = pageSize;
			this.getList();
		},
		// 上下分页
		handleCurrentChange(page) {
			this.paginations.pageIndex = page;
			this.getList();
		},
  },
  activated() {
    /* if (this.reload) {
      this.$store.dispatch("loading/CHNAGE_RELOAD", false);
      Object.assign(this.$data, this.$options.data());
    } */
  },
};
</script>

<style lang="less" scoped>
.fillcontain {
  padding-bottom: 0;
}
.contain {
  background: #fff;
  padding: 10px;
  margin-bottom: 20px;
}
.pagination {
  padding: 10px 20px;
  text-align: right;
}
.operationIcon {
  // padding: 12px;
  border: 1px solid #e5e5e5;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  display: inline-block;
  cursor: pointer;
  box-shadow: 0 0 3px #f9f9f9;
  .svg-icon {
    font-size: 14px;
    fill: #68a3fc;
  }
}
.search_container {
  padding: 20px 20px 0 20px;
}
.handle-btn{
  cursor: pointer;
  color: #409eff;
  display: inline-block;
  padding: 0 8px;
}
</style>